import { onBeforeMount } from "vue"
//主要用于页面刷新之前及时将数据存储到localstore当中
//name 存储的名称 data 数据json类型
export function useLoad(name: string, data: Record<string, any>) {
    onBeforeMount(() => {
        window.addEventListener("beforeunload", () => {
            sessionStorage.setItem(name, JSON.stringify(data));
        });
    })

    function getStorage() {
        return JSON.parse(sessionStorage.getItem(name) || "{}");
    }

    return {
        getStorage
    }
}